<?php
namespace JsonRpc\Services\System;
use JsonRpc\Models\SysInquiry;
use JsonRpc\Models\SysInquiryLine;
use JsonRpc\Models\SysUser;
use JsonRpc\Services\CommonService;
use JsonRpc\Utils\Utils;

/**
 *  用户
 * @author walkor <worker-man@qq.com>
 */
class InquiryService
{
    use CommonService;

    private static function getBaseModel(){
        return "JsonRpc\\Models\\SysInquiry";
    }

    public static function ping(){
        return 'OK';
    }

    public function waitInquiry(){
        $list = SysInquiry::where('is_offer','0')->get();
        if($list){
            return $list;
        }
        return [];
    }

    public function enInquiry(){
        $list = SysInquiry::where('is_offer','1')->get();
        if($list){
            return $list;
        }
        return [];
    }

    public function offerGoods($params){
        $info1 = SysInquiryLine::where('inquiry_id',$params['id'])->get();
        if($info1){
            return $info1;
        }
        return [];
    }

   static function saveData($params){
        $offer_price = $params['offer_price'];
        $goods_id = $params['goods_id'];
        foreach($offer_price as $key => $value){
            if(!empty($value)){
                SysInquiryLine::where('id',$goods_id[$key])->update(['offer_price'=>$value]);
            }
        }
        $id = $params['id'];
        $offer_days = $params['offer_days'];
        $offer_description = $params['offer_description'];
        $offer_time =  date('Y-m-d H:i:s',time());
        SysInquiry::where('id',$id)->update([
            'is_offer' => '1',
            'offerdate' => $offer_time,
            'offer_days' => $offer_days,
            'offer_description' => $offer_description
        ]);
       return true;
    }
}
